package tool;

import java.util.*;

public class YouTool {

    public static List<String> change(Set<String> strings) {
        ArrayList<String> arrayList = new ArrayList<>();
        for (String s : strings) {
            arrayList.add(s);
        }
        return arrayList;
    }
    public static String readerId() {
        Random random = new Random();
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < 8; i++) {
            int id = random.nextInt(9);
            sb.append(id);
        }
        return sb.toString();
    }

    public static String readerID() {
        while (true) {
            Scanner sc = new Scanner(System.in);
            System.out.println("请输入读者编号：");
            String tel = sc.next();
            char c = tel.charAt(0);
            int len = tel.length();
            if (len == 8) {
                for (int i = 1; i <= len - 1; i++) {
                    char t = tel.charAt(i);
                    if (t < '0' || t > '9') {
                        System.out.println("读者编号必须都是数字");
                        break;
                    } else {
                        if (i == len - 1) {
                            System.out.println("");
                            return tel;
                        }
                    }
                }
            } else {
                System.out.println("读者编号长度必须是8位");
            }
        }
    }
    public static String judgmentSex() {
        while (true) {
            System.out.println("输入读者性别");
            String sex = TSUtility.readKeyBoard(1, false);
            if (!(sex.equals("男") || sex.equals("女"))) {
                System.out.println("输入不对，重新输入（男/女）");
            } else {
                return sex;
            }
        }
    }

    public static Boolean judge(String s){
          for(int i=0;i<s.length();i++){
              char c=s.charAt(i);
              if(c<'0'||c>'9'){
                  System.out.println("手机号必须为数字");
                  return false;
              }
              if(i==0&&c!=c){
                  System.out.println("手机号第一位为1");
                  return false;
              }
          }
   return true;
    }

    public static String judgmentPhone(String DefaultValue) {
        for(;;){
            String phone=TSUtility.readString(11,"");
           if(phone.equals("")){
               return DefaultValue;
           }
           if (!judge(phone)){
              continue;
           }
           return phone;
           }
    }

    public static String judgmentPhone() {
        while (true) {
            Scanner sc = new Scanner(System.in);
            System.out.println("请输入手机号：");
            System.out.println("");
            String tel = sc.next();
            char c = tel.charAt(0);
            if (c == '1') {
                int len = tel.length();
                if (len == 11) {
                    for (int i = 1; i <= len - 1; i++) {
                        char t = tel.charAt(i);
                        if (t < '0' || t > '9') {
                            System.out.println("手机号必须都是数字");
                            break;
                        } else {
                            if (i == len - 1) {
                                System.out.println("");
                                return tel;
                            }
                        }
                    }
                } else {
                    System.out.println("手机号长度必须是11位");
                }

            } else {
                System.out.println("手机号必须是1开头");
            }
        }
    }

    public static void main(String[] args) {
        String phone = YouTool.judgmentPhone("123456");
        System.out.println(phone);

    }
}


